<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport"
	      content="width=device-width,initial-scale=1.0,maximum-scale=3,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
	<title>维修师傅客户端</title>
	<link href="css/public/reset-html5.css" rel="stylesheet">
	<link href="css/public/mui.min.css" rel="stylesheet">
	<style>
		.btn-lg {
			padding: 10px 16px;
		}
		
		.mui-input-group .mui-button-row {
			height: auto;
			padding: 5px 0;
		}
	</style>
</head>
<body class="body-bg" id="main">
<img src="../images/logo.png" style="width: 100%">

<form class="mui-input-group mar-top" onsubmit="return false">
	<div class="mui-input-row">
		<label>手机号</label>
		<input type="tel" placeholder="请输入您的手机号码" id="phone">
	</div>
	<div class="mui-input-row">
		<label>验证码</label>
		<input type="tel" id="code" style="width: 32%;float: left" placeholder="请输入验证码">
		<button class="mui-btn mui-btn-warning" id="send_sms" style="float: left;width: auto;margin-top: 1px">发送验证码
		</button>
	</div>
	
	<div class="mui-button-row">
		<button class="mui-btn mui-btn-primary btn-lg" id="bandWeixin">确认认证</button>
	</div>
</form>
</body>
<script src="../js/jquery-2.2.1.min.js"></script>
<script src="../plugins/vue/vue.min.js"></script>
<script src="../js/base.js"></script>
<script src="layer_mobile/layer.js"></script>
<script>
	var submitPhone;
	
	function checkPhone(phone) {
		if (!(/^1[34578]\d{9}$/.test(phone))) {
			alert("手机号码有误，请重填");
			return false;
		}
		return true;
	}
	
	$('#send_sms').on('click', function () {
		var phone = $('#phone').val();
		if (checkPhone(phone)) {
			sendSMS(phone);
			submitPhone = phone;
			$(this).addClass('mui-btn-grey').removeClass('mui-btn-warning').text('短信已发送');
		} else {
		
		}
		
	});
	
	//短信发送
	function sendSMS(phone) {
		var data = {};
		data.phone = phone;
		var index = layer.open({type: 2,shadeClose:false});
		$.post('../index_recycle/index.php?m=Home&c=Master&a=get_phone_code', data, function (res) {
			if (res.code == 200) {
			
			} else {
				alert(res.message);
			}
		layer.close(index);
		}, 'json');
	}
	
	
	//认证维修管理员
	$('#bandWeixin').click(function () {
		var code = $('#code').val();
		if (code.length != 5) {
			alert('验证码格式有误，必须为5位');
			return false;
		}
		var phone = $('#phone').val();
		bandWeixin(phone, code);
	});
	
	
	function bandWeixin(phone, code) {
		var data = {};
		data.phone = phone;
		data.checkCode = code;
		var index = layer.open({type: 2,shadeClose:false});
		$.post('../index_recycle/index.php?m=Home&c=Master&a=binding_wechat_id', data, function (res) {
			if (res.code == 200) {
				location.href = 'index.html';
			} else {
				alert(res.message);
			}
			layer.close(index);
		}, 'json');
	}
</script>
</html>